package com.b2b.controller;

import com.alibaba.fastjson.JSONObject;
import com.b2b.model.common.CategoryHot;
import com.b2b.model.common.ResponseBean;
import com.b2b.model.entity.goods.Goods;
import com.b2b.service.goodsService.GoodsService;
import com.b2b.util.CategoryUtil;
import com.b2b.util.JedisUtil;
import com.b2b.util.common.StatisticUtil;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.testng.annotations.Test;

import javax.xml.ws.Response;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/test")
public class TestController {



    @Autowired
    @Qualifier("restHighLevelClient")
    private RestHighLevelClient client;

    @Autowired
    StatisticUtil statisticUtil;

    @Autowired
    GoodsService goodsService;

    @PostMapping("/add")
    public Object add(@RequestBody Goods goods){
        List<CategoryHot> categoryHotList = new ArrayList<>();
        CategoryHot categoryHot = new CategoryHot();
        categoryHot.setCategoryId(45);
        categoryHot.setSoldTimes(10);
        categoryHotList.add(categoryHot);
        statisticUtil.categoryHot(categoryHotList);
        return JedisUtil.getJson("categoryHot");
    }

    @PostMapping("/addd")
    public Object addd(@RequestBody Goods goods){
        goodsService.insert(goods);
        Integer.parseInt("xawdawd");
        return JedisUtil.getJson("categoryHot");
    }

    //删除文档
    @Test
    void testDeleteDocument() throws IOException {
        DeleteRequest deleteRequest = new DeleteRequest("goods", "o6uqVXwBhZ2mZ7rSMi3V");
        deleteRequest.timeout("1s");
        DeleteResponse deleteResponse = client.delete(deleteRequest, RequestOptions.DEFAULT);
        System.out.println("deleteResponse = " + deleteResponse);

    }

}
